// pages/personal/personal.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		data: '',
		http: getApp().globalData.map
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onShow: function() {
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					data: e.data,
					gr: e.data.gender,
					img:e.data.avatar
				})
				console.log(e)
			}
		})
	},
	tk() {
		this.setData({
			tk: true
		})
	},
	none() {
		this.setData({
			tk: 'false'
		})
	},
	gb(e) {
		wx.request({
			url: getApp().globalData.http + 'action=updateUserInfo&uid=' + this.data.data.uid + '&csname=gender&csvalue=' +
				e.currentTarget.dataset.id,
			success: (res) => {
				console.log(res)
				this.setData({
					tk: 'false',
					gr: e.currentTarget.dataset.id
				})
				wx.setStorage({
					key: 'uid',
					data: res.data.data
				})
			}
		})
	},
	img() {
		wx.showToast({title: '加载中', icon: 'loading'});
		let that=this
		wx.chooseImage({
			count: 1,
			sizeType:'compressed',
			success: (e) => {
				console.log(e)
				wx.uploadFile({
					url: getApp().globalData.http3,
					filePath:e.tempFilePaths[0],
					name:'picturePath',
					success: function(res) {
						let a=JSON.parse(res.data)
						console.log(a)
						wx.request({
							url: getApp().globalData.http + 'action=updateUserInfo&uid=' + that.data.data.uid + '&csname=avatar&csvalue=' +
								a.data.headImage,
							success: (res) => {
								console.log(res)
								that.setData({
									img: res.data.data.avatar
								})
								wx.setStorage({
									key: 'uid',
									data: res.data.data
								})
								wx.hideToast();
							}
						})
					}
				});
			}
		})
	}
})
